package com.duqc.web.controller;

import com.duqc.web.entity.RegionalNetwork;
import com.duqc.web.service.BussinessOptionService;
import com.duqc.springbatch.BussinessOption;
import com.duqc.util.ip.NetworkUtil;
import com.duqc.util.ip.SearcherUtil;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @ClassName BussinessOptionController
 * @Description BussinessOptionController
 * @Author duqc
 * @Date 2022/7/19
 **/
@RestController
@RequiredArgsConstructor
@RequestMapping("/bussiness/option")
public class BussinessOptionController {

    private final BussinessOptionService bussinessOptionService;

    @SneakyThrows
    @GetMapping("list")
    public List<BussinessOption> getList(HttpServletRequest request) {
        return this.bussinessOptionService.selectList();
    }

    @SneakyThrows
    @GetMapping("address")
    public RegionalNetwork address(HttpServletRequest request) {
        String ipAddress = NetworkUtil.getIpAddress(request);
        System.out.println(ipAddress);
        String search = new SearcherUtil().search(ipAddress);
        System.out.println(search);

        RegionalNetwork regionalNetwork = SearcherUtil.regionalAndNetwork("182.150.63.230");
        System.out.println(regionalNetwork);
        return regionalNetwork;
    }

}
